package com.itmuch.cloud.microservicesimpleconsumermovie.hystrix;

import com.itmuch.cloud.microservicesimpleconsumermovie.entity.User;
import com.itmuch.cloud.microservicesimpleconsumermovie.feign.UserFeignClient;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by pactera on 2018/1/24.
 */
@RestController
public class HysTrixController {

    @Autowired
    private UserFeignClient userFeignClient;

    @HystrixCommand(fallbackMethod = "findByIdFallBack")
    @GetMapping("hystrix/user/{id}")
    public User findById(@PathVariable("id") Long id){
        return userFeignClient.findById(id);
    }

    public User findByIdFallBack( Long id){
        User user = new User();
        user.setId(-1L);
        user.setName("默认用户");
        return user;
    }
}
